package cn.img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;



public class Ex3 {
    public static void main(String[] args) {
        var w = 800;
        var h = 800;
        var i = new BufferedImage(w, h, 2);
        var g = i.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setColor(Color.ORANGE);
        g.fillRect(0, 0, w, h);

        g.setColor(Color.WHITE);
        g.fillArc(200,200,400,400,90,180);

        g.setColor(Color.BLACK);
        g.fillArc(200,200,400,400,270,180);
        g.fillOval(300,200,200,200);

        g.setColor(Color.WHITE);
        g.fillOval(350,250,100,100);
        g.fillOval(300,400,200,200);

        g.setColor(Color.BLACK);
        g.fillOval(350,450,100,100);


        g.dispose();
        //保存图像文件
        try {
            ImageIO.write(i, "png", new File("i.png"));
            //打开图像文件
            Runtime.getRuntime().exec("cmd /k start i.png");
        } catch (Exception e) {

        }
    }
}
